/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>

#include "sle_error_code.h"
#include "sle_host_stub.h"
#include "sle_host_callback_stub.h"
#include "sle_host_proxy.h"

class SleHostStubTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp() override;
    void TearDown() override;

};
void SleHostStubTest::SetUp()
{
}

void SleHostStubTest::TearDown()
{
}

void SleHostStubTest::SetUpTestCase()
{
}

void SleHostStubTest::TearDownTestCase()
{
}

namespace OHOS {
namespace NearLink {
namespace SleStandard {

class SleHostStubMock : public SleHostStub {
    public:
        SleErrorCode RegisterHostCallback(const sptr<ISleHostCallback> &callback)
        {
            return SLE_NO_ERROR;
        }
        SleErrorCode UnregisterHostCallback(const sptr<ISleHostCallback> &callback)
        {
            return SLE_NO_ERROR;
        }
        SleErrorCode EnableSle()
        {
            return SLE_NO_ERROR;
        }
        SleErrorCode DisableSle()
        {
            return SLE_NO_ERROR;
        }
        SleErrorCode GetSleState(int32_t &state)
        {
            state = 1;
            return SLE_NO_ERROR;
        }
        SleErrorCode GetHostAddress(SleAddress &address)
        {
            return SLE_NO_ERROR;
        }
        SleErrorCode SetHostName(const std::string name)
        {
            return SLE_NO_ERROR;
        }
        SleErrorCode GetHostName(std::string &name)
        {
            name = "test";
            return SLE_NO_ERROR;
        }
        SleErrorCode StartFlowMonitor()
        {
            return SLE_NO_ERROR;
        }
        SleErrorCode StopFlowMonitor()
        {
            return SLE_NO_ERROR;
        }
        SleErrorCode GetHostDefaultConnectConfig(SleConnectConfig &hostConnParam)
        {
            hostConnParam.connectInterval = 1;
            hostConnParam.connectTimeout = 1;
            hostConnParam.connectLatency = 1;
            hostConnParam.mtuSize = 1;

            hostConnParam.mcs = 1;
            hostConnParam.pilotDensity = 1;
            hostConnParam.formatType = 1;
            hostConnParam.phy = 1;
            hostConnParam.dataLen = 1;
            return SLE_NO_ERROR;
        }
        sptr<IRemoteObject> GetSleServerRemote(const std::string &name)
        {
            return nullptr;
        }
};

class SleHostCallbackStubMock : public SleHostCallbackStub {
    public:
        void OnSleStateChange(int32_t state)
        {

        }
        void OnFlowMonitorEvent(float flow)
        {

        }

};


/************************************************communication/nearlink/sle/sle_standard/frameworks/ipc/source******************************************************** */
HWTEST_F(SleHostStubTest, OnSleStateChangeInner_201, testing::ext::TestSize.Level0)
{
    SleHostCallbackStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostCallbackStub::GetDescriptor());

    data.WriteInt32(1);
    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_CALLBACK_STATE_CHANGE, data, reply, option), NO_ERROR);
}

HWTEST_F(SleHostStubTest, OnFlowMonitorEventInner_201, testing::ext::TestSize.Level0)
{
    SleHostCallbackStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostCallbackStub::GetDescriptor());

    data.WriteFloat(1.0);
    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_CALLBACK_FLOW_MONITOR_EVENT, data, reply, option), NO_ERROR);
}






/************************************************communication/nearlink/sle/sle_standard/services/ipc******************************************************** */
HWTEST_F(SleHostStubTest, RegisterHostCallbackInner_001, testing::ext::TestSize.Level0)
{
    SleHostStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostStub::GetDescriptor());

    sptr<IRemoteObject> remoteObject = new SleHostCallbackStubMock();
    data.WriteRemoteObject(remoteObject);

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_REGISTER_HOST_CALLBACK, data, reply, option), NO_ERROR);
}
/******************************************************************************************************** */


HWTEST_F(SleHostStubTest, UnregisterHostCallbackInner_001, testing::ext::TestSize.Level0)
{
    SleHostStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostStub::GetDescriptor());

    sptr<IRemoteObject> remoteObject = new SleHostCallbackStubMock();
    data.WriteRemoteObject(remoteObject);

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_UNREGISTER_HOST_CALLBACK, data, reply, option), NO_ERROR);
}
/******************************************************************************************************** */

HWTEST_F(SleHostStubTest, EnableSleInner_001, testing::ext::TestSize.Level0)
{
    SleHostStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostStub::GetDescriptor());

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_ENABLE, data, reply, option), NO_ERROR);
}
/******************************************************************************************************** */

HWTEST_F(SleHostStubTest, DisableSleInner_001, testing::ext::TestSize.Level0)
{
    SleHostStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostStub::GetDescriptor());

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_DISABLE, data, reply, option), NO_ERROR);
}
/******************************************************************************************************** */

HWTEST_F(SleHostStubTest, GetSleStateInner_001, testing::ext::TestSize.Level0)
{
    SleHostStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostStub::GetDescriptor());

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_GET_SLE_STATE, data, reply, option), NO_ERROR);
}
/******************************************************************************************************** */

HWTEST_F(SleHostStubTest, GetHostAddressInner_001, testing::ext::TestSize.Level0)
{
    SleHostStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostStub::GetDescriptor());

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_GET_HOST_ADDRESS, data, reply, option), NO_ERROR);
}
/******************************************************************************************************** */

HWTEST_F(SleHostStubTest, SetHostNameInner_001, testing::ext::TestSize.Level0)
{
    SleHostStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostStub::GetDescriptor());

    data.WriteString("test");
    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_SET_HOST_NAME, data, reply, option), NO_ERROR);
}
/******************************************************************************************************** */

HWTEST_F(SleHostStubTest, GetHostNameInner_001, testing::ext::TestSize.Level0)
{
    SleHostStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostStub::GetDescriptor());

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_GET_HOST_NAME, data, reply, option), NO_ERROR);
}
/******************************************************************************************************** */


HWTEST_F(SleHostStubTest, GetHostDefaultConnectConfigInner_001, testing::ext::TestSize.Level0)
{
    SleHostStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostStub::GetDescriptor());

    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_GET_DEFAULT_CONN_CONFIG, data, reply, option), NO_ERROR);
}
/******************************************************************************************************** */

HWTEST_F(SleHostStubTest, GetSleServerRemoteInner_001, testing::ext::TestSize.Level0)
{
    SleHostStubMock ssapClient;
    MessageParcel data;
    MessageParcel reply;
    MessageOption option;
    data.WriteInterfaceToken(SleHostStub::GetDescriptor());

    data.WriteString("test");
    EXPECT_EQ(ssapClient.OnRemoteRequest(SLE_GET_SLE_SERVER_REMOTE, data, reply, option), NO_ERROR);
}
/******************************************************************************************************** */


}}}